import {defineStore} from 'pinia'
import {ref} from "vue";
import request from "../utils/request.js";
import {Modal} from "@opentiny/vue";

export const useAsideStore = defineStore('aside', () => {
    const existFlag = ref(false) // 是否存在
    const asideWidth = ref('150px') // 侧边栏宽度
    const resourceData = ref([]) // 菜单数据
    const expandeArr = ref([201]) // 默认展开菜单

    const queryResourceMenuData = () => {
        // 查询资源菜单数据
        request.get('/api/systems/tags/tree').then(res => {
            if (res.code === 1){
                resourceData.value = res.data.map(tag => {
                    const temp = {
                        children:[]
                    }
                    temp.id = tag.id
                    temp.label = tag.name
                    temp.children = tag.children.map(v => {
                        const tmp = {
                            id:0,
                            label:''
                        }
                        tmp.id = v.id
                        tmp.label = v.name
                        return tmp
                    })
                    return temp
                })
            }else {
                Modal.message({message: res.message, status: 'error'})
            }
        })
    }
    return {
        existFlag, asideWidth, resourceData, expandeArr,
        queryResourceMenuData
    }
})
